﻿using System;
using System.Data;
using System.Configuration; 
using System.Web;
using System.Web.Security;
using System.Web.UI; 
using System.IO;

namespace Runda.CMS.Portal
{
    public class WebUtility
    {
        public static void DownloadFile(string fullpath, string filename, string contentType)
        {
            if (!File.Exists(fullpath)) return;
            if (string.IsNullOrEmpty(filename))
            {
                filename = HttpUtility.UrlEncode(Path.GetFileName(fullpath)).Replace("+", "%20");
            }
            if (string.IsNullOrEmpty(contentType))
            {
                contentType = "application/octet-stream";
            }
            byte[] data = File.ReadAllBytes(fullpath);
            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.ContentType = contentType;
            HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;FileName=" + filename);
            HttpContext.Current.Response.BinaryWrite(data);
            HttpContext.Current.Response.Flush();
            HttpContext.Current.Response.End();
        }

    }
}
